package com.jshan.blog.base.admin.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.jshan.blog.valid.AddGroupValid;
import com.jshan.blog.valid.UpdateGroupValid;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 *
 * @TableName sys_menu
 */
@TableName(value ="sys_menu")
@Data
@Schema(description = "菜单entity")
public class SysMenu implements Serializable {
    /**
     * 菜单 id
     */
    @TableId(type = IdType.AUTO)
    @NotNull(message = "菜单 id 不能为空", groups = {UpdateGroupValid.class})
    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "状态")
    private Integer isStatus;
    /**
     * 父级 id
     */
    @Schema(description = "父级id")
    private Long pid;

    /**
     * 路径
     */
    @Schema(description = "路径")
    @NotNull(message = "菜单路径不能为空", groups = {AddGroupValid.class, UpdateGroupValid.class})
    private String path;

    /**
     * 路径名称
     */
    @Schema(description = "路径名称")
    private String name;

    /**
     * 菜单名称
     */
    @Schema(description = "菜单名称")
    @NotNull(message = "菜单名称不能为空", groups = {AddGroupValid.class, UpdateGroupValid.class})
    private String label;

    /**
     * 图标
     */
    @Schema(description = "图标")
    private String icon;

    /**
     * 具体路径 但是设计为和 name 一致
     */
    @Schema(description = "路径url和path一致即可")
    @NotNull(message = "路径 url 不能为空", groups = {AddGroupValid.class, UpdateGroupValid.class})
    private String url;

    /**
     * 排序
     */
    @Schema(description = "排序，数值越小越优先")
    private Integer sort;

    /**
     * 层级
     */
    @Schema(description = "层级，几级菜单")
    private Integer deep;

    /**
     * 菜单类型
     */
    @Schema(description = "菜单类型")
    private String menuTypeCd;

    /**
     * 权限
     */
    @Schema(description = "权限")
    private String permissions;

    /**
     * 是否有子集
     */
    @Schema(description = "是否有子集")
    private Integer hasChildren;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @Schema(description = "创建人id")
    private Integer createId;

    /**
     * 更新人
     */
    @Schema(description = "更新人id")
    private Integer updateId;

    /**
     * 是否删除
     */
    @TableLogic
    private Integer isDelete;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}
